package lg.minecraft.plugin.cobblemoncore.config.mapping;

import com.cobblemon.mod.common.pokemon.Gender;
import lg.minecraft.plugin.cobblemoncore.LGCobblemonCore;
import lg.minecraft.plugin.cobblemoncore.util.LocalizedName;
import lombok.Getter;

/**
 * @author langle__
 * @version 1.0
 */
@Getter
public class GenderMapping extends AbstractMapping<Gender> {

    public GenderMapping() {
        super(LGCobblemonCore.getInstance(), "gender.yml", LGCobblemonCore.getMappingDirectory().getPath());
    }

    @Override
    protected boolean isUseLocalFile() {
        return LGCobblemonCore.getMainConfig().isGender();
    }

    @Override
    protected void loadFromDynamicSource() {
        for (Gender gender : Gender.values()) {
            String displayName = LocalizedName.getGenderName(gender);
            set(gender.name().toLowerCase(), displayName);
            mapping.put(displayName, gender);
            reverse.put(gender, displayName);
        }
    }

    @Override
    protected void loadFromLocalFile() {
        for (String key : getKeys(false)) {
            String value = getString(key);
            Gender gender;
            try {
                gender = Gender.valueOf(key.toUpperCase());
            } catch (Exception e) {
                getPlugin().getLogger().warning("Gender " + key + " not found!");
                continue;
            }
            mapping.put(value, gender);
            reverse.put(gender, value);
        }
    }

}

